home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / arkanoid.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  2KB  |  127 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11.  
  12.  
  13.  
  14. int arkanoid_paddle_select;
  15.  
  16. static int z80write,fromz80,m68705write,toz80;
  17.  
  18. static unsigned char portA_in,portA_out,ddrA;
  19. static unsigned char portC_out,ddrC;
  20.  
  21. FILE *thelog;
  22.  
  23. void arkanoid_init_machine(void)
  24. {
  25.     portA_in = portA_out = z80write = m68705write = 0;
  26. }
  27.  
  28. READ_HANDLER( arkanoid_Z80_mcu_r )
  29. {
  30.     /* return the last value the 68705 wrote, and mark that we've read it */
  31.     m68705write = 0;
  32.     return toz80;
  33. }
  34.  
  35. WRITE_HANDLER( arkanoid_Z80_mcu_w )
  36. {
  37.     /* a write from the Z80 has occurred, mark it and remember the value */
  38.     z80write = 1;
  39.     fromz80 = data;
  40.  
  41.     /* give up a little bit of time to let the 68705 detect the write */
  42.     cpu_spinuntil_trigger(700);
  43. }
  44.  
  45. READ_HANDLER( arkanoid_68705_portA_r )
  46. {
  47.     return (portA_out & ddrA) | (portA_in & ~ddrA);
  48. }
  49.  
  50. WRITE_HANDLER( arkanoid_68705_portA_w )
  51. {
  52.     portA_out = data;
  53. }
  54.  
  55. WRITE_HANDLER( arkanoid_68705_ddrA_w )
  56. {
  57.     ddrA = data;
  58. }
  59.  
  60.  
  61. READ_HANDLER( arkanoid_68705_portC_r )
  62. {
  63.     int res=0;
  64.  
  65.     /* bit 0 is high on a write strobe; clear it once we've detected it */
  66.     if (z80write) res |= 0x01;
  67.  
  68.     /* bit 1 is high if the previous write has been read */
  69.     if (!m68705write) res |= 0x02;
  70.  
  71.     return (portC_out & ddrC) | (res & ~ddrC);
  72. }
  73.  
  74. WRITE_HANDLER( arkanoid_68705_portC_w )
  75. {
  76.     if ((ddrC & 0x04) && (~data & 0x04) && (portC_out & 0x04))
  77.     {
  78.         /* mark that the command has been seen */
  79.         cpu_trigger(700);
  80.  
  81.         /* return the last value the Z80 wrote */
  82.         z80write = 0;
  83.         portA_in = fromz80;
  84.     }
  85.     if ((ddrC & 0x08) && (~data & 0x08) && (portC_out & 0x08))
  86.     {
  87.         /* a write from the 68705 to the Z80; remember its value */
  88.         m68705write = 1;
  89.         toz80 = portA_out;
  90.     }
  91.  
  92.     portC_out = data;
  93. }
  94.  
  95. WRITE_HANDLER( arkanoid_68705_ddrC_w )
  96. {
  97.     ddrC = data;
  98. }
  99.  
  100.  
  101.  
  102. READ_HANDLER( arkanoid_68705_input_0_r )
  103. {
  104.     int res = input_port_0_r(offset) & 0x3f;
  105.  
  106.     /* bit 0x40 comes from the sticky bit */
  107.     if (!z80write) res |= 0x40;
  108.  
  109.     /* bit 0x80 comes from a write latch */
  110.     if (!m68705write) res |= 0x80;
  111.  
  112.     return res;
  113. }
  114.  
  115. READ_HANDLER( arkanoid_input_2_r )
  116. {
  117.     if (arkanoid_paddle_select)
  118.     {
  119.         return input_port_3_r(offset);
  120.     }
  121.     else
  122.     {
  123.         return input_port_2_r(offset);
  124.     }
  125. }
  126.  
  127.